package cn.edu.scau.cmi.wuzhenxin.hibernate.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;;

public class ScauCmiHibernateSessionFactoryUtil {
	private static SessionFactory sessionFactory;
	
	public static SessionFactory getSessionFactory() {
		if(sessionFactory == null) {//单例模式
			//创建配置对象  
	        Configuration config = new Configuration().configure();
	        //创建会话工厂对象  
	        sessionFactory = config.buildSessionFactory();
		}
		return sessionFactory;
	}
	
	public static Session getSession(){
		Session session= getSessionFactory().openSession();
		return session;
	}
}